package logic

import (
	"context"

	"demohttp/internal/svc"
	"demohttp/internal/types"

	"gitee.com/fish2016/demorpc/demorpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type DemohttpLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDemohttpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DemohttpLogic {
	return &DemohttpLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DemohttpLogic) Demohttp(req *types.Request) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	resp = new(types.Response)
	resp.Message = req.Name
	rpcResp, err := l.svcCtx.DemorpcClient.Ping(l.ctx, &demorpc.Request{Ping: "ping"})
	if err != nil {
		return nil, err
	}

	resp.Message = rpcResp.Pong
	return &types.Response{
		Message: rpcResp.Pong,
	}, nil
}
